package org.digitaldomination.thefinalcountdown;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MotionEvent;

public class Intro extends Activity {

	MediaPlayer mpsplash;
	protected boolean _active = true;
	protected int _splashTime = 5000;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);

		mpsplash = MediaPlayer.create(this, R.raw.countdown);
		mpsplash.start();

		Thread splashTread = new Thread() {
			@Override
			public void run() {
				try {
					int waited = 0;
					while (_active && (waited < _splashTime)) {
						sleep(100);
						if (_active) {
							waited += 100;
						}
					}
				} catch (InterruptedException e) {
					
				} finally {
					Intent startcounter = new Intent(Intro.this, Countdown.class);
					startActivity(startcounter);
					finish();
				}
			}
		};
		splashTread.start();
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			_active = false;
		}
		return true;
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		mpsplash.release();
	}

	@Override
	protected void onPause() {
		super.onPause();
		mpsplash.pause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		mpsplash.start();
	}

}